// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  const { OPENID } = cloud.getWXContext() // 拿到openid
  const result = await cloud.openapi.wxacode.getUnlimited({ // 调用API拿到小程序码数据
	  scene: OPENID
  })
  const upload = await cloud.uploadFile({
	  cloudPath: 'qrcode/' + Date.now()+ '_' + Math.random() + '.png', // 传到对应存储中
	  fileContent: result.buffer // 转换为buffer
  })
  return upload.fileID // 将fileID返回给前端
}